﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Forums.ForumsClient.Models;
using System.Diagnostics;
using System.Globalization;


namespace Microsoft.Forums.ForumsClient.Views
{
    /// <summary>
    /// Interaction logic for PostView.xaml
    /// </summary>
    public partial class PostView : UserControl
    {
        public PostView()
        {
            InitializeComponent();
        }

        public static readonly DependencyProperty HtmlSourceProperty =
            DependencyProperty.Register(
            "HtmlSource",
            typeof(string),
            typeof(PostView),
            new PropertyMetadata(new PropertyChangedCallback(OnHtmlSourceChanged)));


        /// <summary>
        /// Gets or sets the HTML source.
        /// </summary>
        /// <value>The HTML source.</value>
        public string HtmlSource
        {
            get
            {
                return (string)this.GetValue(HtmlSourceProperty);
            }
            set
            {
                this.SetValue(HtmlSourceProperty, value);
            }
        }

        /// <summary>
        /// Called when HTML source changed.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        static void OnHtmlSourceChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
        {
            PostView view = source as PostView;
            if (view != null)
            {
                if (e.NewValue == null)
                {

                    // clear browser window
                    view.webBrowser.Source = null;
                    return;
                }
                else
                {
                    string html = e.NewValue as string;
                    view.webBrowser.NavigateToString(html);
                }
            }
        }
    }
}
